import React from 'react';
import { Spin } from 'antd';
import { useRequest, defaultFormatResult } from '@/hooks';
import { InterviewQuestionMobile, Result, Button } from '@/pages/RecruitEmail/mobile/components';
import { getRecruitmentInfoByEncryptId } from '@/services/user';
import { STATUS } from '@/pages/RecruitEmail/constants';
import BizIcon from '@/components/BizIcon';
// import moment from 'moment';
import { printScreenDown } from '@/pages/EntryManage/utils';
import styles from './index.less';

// 劳动合同类型单位
const LABOUR_PERIOD_TYPE = [
    { value: 1, text: '年' },
    { value: 2, text: '月' }
];

// 试用期类型单位
const PROBATION_PERIOD_TYPE = [
    { value: 1, text: '月' },
    { value: 2, text: '天' }
];

function InterviewJoin(props) {
    const { nid, getTotalDesc } = props;

    const { data, loading } = useRequest(() => getRecruitmentInfoByEncryptId({ employId: nid }), {
        ...defaultFormatResult
    });

    // const infoData = React.useMemo(() => {
    //     if (data) {
    //         const {
    //             offerEffectiveValue = 48,
    //             talentName = '',
    //             talentSex = '',
    //             probationPeriodNumber = 0,
    //             probationPeriodType = 1,
    //             officialMonthSalary = '',
    //             labourPeriodNumber = '',
    //             labourPeriodType = 1,
    //             suggestedEntryTime = '',
    //             sendTime = '',
    //             departmentName = '',
    //             dutyName = '',
    //             companyAddress = ''
    //         } = data;
    //         const quarterPerformance = officialMonthSalary ? ((officialMonthSalary * 1.5) / 4).toFixed(0) : '0';
    //         const halfYearPerformance = officialMonthSalary ? ((officialMonthSalary * 1.5) / 2).toFixed(0) : '0';

    //         const deActivateTime = moment(sendTime || new Date())
    //             .add(offerEffectiveValue, 'hour')
    //             .format('YYYY-MM-DD HH:mm');
    //         return {
    //             offerEffectiveValue,
    //             talentName,
    //             talentSex,
    //             probationPeriodNumber,
    //             probationPeriodType,
    //             officialMonthSalary,
    //             labourPeriodNumber,
    //             labourPeriodType,
    //             suggestedEntryTime,
    //             sendTime,
    //             departmentName,
    //             dutyName,
    //             companyAddress,
    //             quarterPerformance,
    //             halfYearPerformance,
    //             deActivateTime
    //         };
    //     }
    //     return null;
    // }, [JSON.stringify(data)]);

    const list = React.useMemo(() => {
        let resultList = [];
        const { labourPeriodNumber, labourPeriodType, probationPeriodNumber, probationPeriodType } = data || {};
        let serviceTimeRange = '';
        // 服务年限年限
        serviceTimeRange +=
            labourPeriodNumber === -1
                ? '无固定期限'
                : `${labourPeriodNumber}${LABOUR_PERIOD_TYPE.find(item => item.value === labourPeriodType)?.text}`;
        // 试用期

        serviceTimeRange += `，包含${probationPeriodNumber}${probationPeriodType === 1 ? '个' : ''}${
            PROBATION_PERIOD_TYPE.find(item => item.value === probationPeriodType)?.text
        }试用期`;
        if (data) {
            // 已提交面试作业
            resultList = [
                {
                    key: '任职部门：',
                    value: data?.departmentName
                },
                {
                    key: '任职岗位：',
                    value: data?.dutyName
                },
                {
                    key: '入职时间：',
                    value: data?.suggestedEntryTime
                },
                {
                    key: '服务期限：',
                    value: serviceTimeRange
                }
            ];
        }
        return resultList;
    }, [data]);
    const pageContent = (
        <div
            id="printPage"
            style={{
                paddingLeft: 16,
                paddingRight: 16,
                paddingTop: 24,
                paddingBottom: 24,
                width: '100%',
                position: 'absolute',
                zIndex: -1000,
                fontSize: 12,
                wordBreak: 'break-all',
                top: '-999999999px'
            }}
        >
            <div dangerouslySetInnerHTML={{ __html: data?.templateContent }} />
        </div>
    );
    return (
        <div className={styles.interviewMobile}>
            <div className={styles.fakeItem} style={{ background: '#fff' }}></div>

            <div>
                <Spin spinning={loading}>
                    <>
                        <div style={{ background: '#fff' }}>
                            <>
                                <Result
                                    type={STATUS.ACCEPT}
                                    title="已接受录用"
                                    content="为了给您提供更好入职体验，请您根据指引完成入职准备"
                                />
                                <div className={styles.ph16}>
                                    <Button
                                        type="primary"
                                        onClick={() => {
                                            sessionStorage.setItem('__LETTER_STEP__', '');
                                            getTotalDesc();
                                        }}
                                    >
                                        入职准备
                                    </Button>
                                </div>
                            </>
                        </div>
                        <div className={styles.con1}>
                            <div className={styles.interviewInfo}>录用信息</div>
                            <InterviewQuestionMobile list={list} />
                            <div className={styles.line}></div>
                            <a
                                className={styles.download}
                                onClick={() => {
                                    // doPrint3();
                                    printScreenDown(document.querySelector('#printPage'), '录用通知书');
                                }}
                            >
                                <BizIcon
                                    type="listfunction_viewinterview_icon_default"
                                    style={{ marginRight: '8px' }}
                                ></BizIcon>
                                查看录用通知书
                            </a>
                        </div>
                        {data && pageContent}
                    </>
                </Spin>
            </div>
        </div>
    );
}

export default InterviewJoin;
